﻿using System;
using System.Web.Mvc;
using Xoohoo.Extensions;
using Xoohoo.Models.ViewModels;

namespace Xoohoo.Html
{
    public static class CssExtensions
    {
        #region RenderCssFile

        public static void RenderCssFile<TModel>(this HtmlHelper<TModel> htmlHelper, string path) where TModel : XoohooViewModel
        {
            htmlHelper.RenderCssFile(path, null);
        }
        public static void RenderCssFile<TModel>(this HtmlHelper<TModel> htmlHelper, string path, string releasePath) where TModel : XoohooViewModel
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }

#if DEBUG
#else
            if (!string.IsNullOrEmpty(releasePath))
                path = releasePath;
#endif

            if (!(path.StartsWith("http://") || path.StartsWith("https://")))
            {
                UrlHelper urlHelper = new UrlHelper(htmlHelper.ViewContext.RequestContext);

                path = !path.StartsWith("/")
                    ? urlHelper.StylePath(path, htmlHelper.ViewContext)
                    : urlHelper.AppPath(path);
            }

            htmlHelper.ViewContext.Writer.Write(
                htmlHelper.HeadLink("stylesheet", path, "text/css", String.Empty)
                );
        }

        #endregion

    }
}
